import os import sys from os import listdir from os.path import isfile, isdir, join print ("change py files to txt files") def changePyFilesToTxtFiles(currentPath, currentFolder, depth): #print(currentPath) currentFiles = [ f for f in listdir(currentPath) if isfile(join(currentPath,f)) ] currentDirs = [ f for f in listdir(currentPath) if isdir(join(currentPath,f)) ] for file in currentFiles: if file.endswith(".py"): newFileName = file.replace('.py','.txt') os.rename(currentPath + '\\' + file,currentPath + '\\' +newFileName) print ("changing: " + file) for folder in currentDirs: changePyFilesToTxtFiles(currentPath + "\\" + folder, folder, depth + 1) startpath = os.getcwd() currentDirs = [ f for f in listdir(startpath) if isdir(join(startpath,f)) ] for folder in currentDirs: changePyFilesToTxtFiles(startpath + "\\" + folder, folder, 0)